/**
 * 
 */
package io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import game.TileType;

/**
 * @author Remi REBILLARD
 *
 */
public class ImportTileType {
	private BufferedReader buffer;
	
	private String header;
	private String[] content;
	
	/**
	 * @param inputstream
	 */
	public ImportTileType( InputStream is ){
		this.buffer = new BufferedReader( new InputStreamReader( is ) );
	}
	
	/**
	 * @return the data of file for TileType
	 */
	public ArrayList< TileType > read() throws IOException{
		
		ArrayList< TileType > data = new ArrayList< TileType >();
		header = buffer.readLine();
		
		if( !header.equals( "game_db_tiles\t1" ) )
			throw new IOException( "Invalid Header of TileType" );
		
		while( buffer.ready() ){
			
			content = buffer.readLine().split( "\t" );
			TileType tmpTile = new TileType
			(
				Integer.parseInt( content[0] ),	//TILE
				content[1],						//TYPE
				content[2],						//IMAGE
				Integer.parseInt( content[3] )	//DEFENSE
			);
			data.add( tmpTile );
		}
		return data;
	}
}
